package bdz.projects.sc.support
{
	import bdz.projects.sc.events.SCEvent;
	
	import com.greensock.TweenMax;
	import com.greensock.easing.Strong;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class SCStartPanel extends MovieClip
	{
		private var startSelection:SCStartSelection;
		private var startFooter:MovieClip;
		private var selectedRace:String;
		public function SCStartPanel()
		{
			super();
			addEventListener(Event.ADDED_TO_STAGE, initializeComponent);
			
		}
		private function initializeComponent(evt:Event):void{
			startSelection = new StartScreenSelection();
			startSelection.x = Math.ceil(stage.stageWidth*.5);
			startSelection.y = Math.ceil(stage.stageHeight*.5);
			startSelection.addEventListener(SCEvent.RACE_SELECT, onRaceSelection);
			addChild(startSelection);
			
			startFooter = new StartScreenFooter();
			startFooter.addEventListener(SCEvent.NOTIFY_START, onNotifyStart);
			addChild(startFooter);
		}
		protected function onRaceSelection(evt:SCEvent):void{
			selectedRace = evt.data;
		}
		protected function onNotifyStart(evt:SCEvent):void{
			if(selectedRace != null){
				dispatchEvent(new SCEvent(SCEvent.START_SELECTION_COMPLETE, {selectedRace:selectedRace}));
			}
		}
		public function remove():void{
			TweenMax.to(startSelection, .6, {alpha:0, colorMatrixFilter:{colorize:0xffffff, amount:3}, scaleX:1.1, scaleY:1.1, ease:Strong.easeInOut, onComplete:removeChild, onCompleteParams:[startSelection]});
			TweenMax.to(startFooter, .6, {y:stage.stageHeight+(startFooter.height*2), ease:Strong.easeInOut, onComplete:removeChild, onCompleteParams:[startFooter]});
			TweenMax.delayedCall(1.2, parent.removeChild, [this]);
		}
	}
}